//    Copyright (C) Kherty.  All rights reserved.
using System.Diagnostics;
using System.Diagnostics.Contracts;

namespace OpenLS.Spreadsheet.Expressions
{
    internal class StringConstantExpression : ConstantExpression
    {
        public override string ToString()
        {
            return "\"" + this.StringValue + "\"";
        }
        public bool ForceString;

        public StringConstantExpression(string value)
        {
            Contract.Requires(value != null);
            StringValue = value;
        }

        public StringConstantExpression(string value, bool forceString)
            : this(value)
        {
            this.ForceString = forceString;
        }

        public string StringValue { get; set; }

        public override object Value
        {
            get { return StringValue; }
        }

        public override string GetText(TextContext context)
        {
            if (ForceString)
                return "'" + StringValue;
            return "\"" + StringValue.Replace("\"", "\"\"") + "\"";
        }
    }
}